from toolclass.random_number import random_number
from toolclass.time_samp import TimeStamp
import requests
from lib.md5_hash import Md5Hash

timestamp = TimeStamp()

class PlaceOrderTest():
    def setUp(self):
        print("**************************开始执行************************")

    def tearDown(self):
        print("-------------------------执行结束-------------------------")

    def order_number(self):
        timesamp = timestamp.time10()
        # 生成签名
        data = {
            "accountType":"1",
            "merchantId":"22988",
            "number":"1",
            "outTradeNo":"adc"+str(random_number()),
            "productId":"107",
            "rechargeAccount":"18380416326",
            "timeStamp":str(timesamp),
            "key":"3e7bc3da64191001a5d7f5053e7ab"
        }

        param = '&'.join([k + '=' + v for k, v in data.items()])
        sign = Md5Hash().md5_hash(param).upper()

        payload = {"merchantId":data["merchantId"],"outTradeNo": data["outTradeNo"], "productId": data["productId"],"rechargeAccount": data["rechargeAccount"], "accountType": data["accountType"], "timeStamp": data["timeStamp"], "number":data["number"],"sign":sign}
        headers = {
            "Content-Type": "application/x-www-form-urlencoded"
        }
        print("paload:",payload)
        url = "http://test.openapi.1688sup.cn/recharge/order"
        r = requests.post(url=url,headers=headers,data=payload)
        resp = r.text
        print(resp)
        return payload["outTradeNo"]

if __name__ == "__main__":
    PlaceOrderTest().order_number()
